package com.gh.ggkt.vod.service.impl;

import com.atguigu.ggkt.model.vod.Video;
import com.gh.ggkt.vod.mapper.VideoMapper;
import com.gh.ggkt.vod.service.VideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gh.ggkt.vod.service.VodService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author Eric Fang
 * @since 2022-09-11
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    @Autowired
    private VodService vodService;

    /**
     * 删除小节，同时删除小节中的视频
     * @param id
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void removeVideo(Long id) {
        Video video = baseMapper.selectById(id);
        //获取video视频id
        String videoSourceId = video.getVideoSourceId();
        if(StringUtils.isNotEmpty(videoSourceId)){
            vodService.removeVideo(videoSourceId);
        }
        //根据id删除小节
        baseMapper.deleteById(id);
    }
}
